<template>
  <div class="w-full h-[calc(100vh-150px)] overflow-y-auto text-sm p-1">
    <div
      v-for="(item, index) of AiSessionList"
      :class="ActiveClass(item)"
      class="w-[90%] h-[55px] m-auto flex flex-col justify-between mb-4 px-3 py-1 rounded sessionItem"
      @click="SelecteSessionItem(item)"
    >
      <div class="flex flex-row justify-between items-center">
        <p>{{ item.title }}-{{ index }}</p>
        <span
          class="iconfont icon-guanbi cursor-pointer"
          style="font-size: 10px"
          @click.stop="ai.DeleteSession(item.id)"
        ></span>
      </div>

      <div class="text-end text-white text-[10px]">
        <span>{{ FormatTime(item.updatedAt) }}</span>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { storeToRefs } from "pinia";
import { IAISession } from "@/types/ai";
import { UseAI } from "@/store/modules/ai";
import { FormatTime } from "@/utils/time.ts";

const ai = UseAI();
const { AiSessionList, ActiveSessionId, AiMessageType } = storeToRefs(ai);

function ActiveClass(item: IAISession) {
  return ActiveSessionId.value === item.id ? "bg-[skyblue]" : "bg-slate-500";
}

function SelecteSessionItem(item: IAISession) {
  AiMessageType.value = "message";
  ActiveSessionId.value = item.id;
}

ai.GetSessionList();
</script>

<style lang="scss" scoped>
.sessionItem {
  cursor: pointer;
  transition: all 0.3s ease-in-out;
  box-shadow: rgba(100, 100, 111, 0.2) 0px 7px 29px 0px;
}

.sessionItem:hover {
  transform: scale(1.05);
  background-color: skyblue;
}
</style>
